import os
import shutil
import GetModelValue

def include_str_mod(modelpath,include_str):
    model = GetModelValue.GetModelValue(modelpath)
    if not model.TEXS.is_None and len(model.TEXS.texture) > 0:
        for texture in model.TEXS.texture:
            if include_str in texture['filename'].decode('gbk').strip(b'\x00'.decode()):
                return True

    return False


def Movefile(importPath,exportPath,include_str):
    if os.path.exists(exportPath) :
        for root, dirs, files in os.walk(importPath):
            for file in files:
                namepath = root + "\\" + file
                if os.path.exists(namepath):
                    if include_str in file or ('.mdx' == file[-4:] and include_str_mod(namepath,include_str)):
                        for root, dirs, files in os.walk(root):
                            for file in files:
                                if os.path.exists(exportPath + '\\' + file):
                                    _str = ''
                                    for root, dirs, files in os.walk(root):
                                        for file in files:
                                            if os.path.exists(exportPath + '\\' + file):
                                                _str += "importPath\t%s\t%s\n" % (os.path.basename(root + "\\" + file),os.path.getsize(root + "\\" + file))
                                                _str += "exportPath\t%s\t%s\n\n" % (os.path.basename(exportPath + '\\' + file),os.path.getsize(exportPath + '\\' + file))
                                    print(_str)
                                    os.system('pause')
                                else:
                                    shutil.move(root+'\\'+file,exportPath)
# 清理空文件夹
        for root, dirs, files in os.walk(importPath):
            for dir in dirs:
                path = root + '\\' + dir
                if not os.listdir(path):
                    os.rmdir(path)
    else:
        print("去TM的没这个目录")

Movefile('G:\\素材汇集\\模型地图\\装饰物模型\\临时','G:\\素材汇集\\模型地图\\装饰物模型\\某个煞笔','941442872')